package com.atguigu.common;

import com.github.difflib.patch.AbstractDelta;
import com.github.difflib.patch.DeltaType;
import com.github.difflib.patch.Patch;

public class DiffCounter {
    private long equal = 0;
    private long diff = 0;

    public DiffCounter(Patch<String> patch) {
        for (AbstractDelta<String> delta : patch.getDeltas()) {
            if (delta.getType() == DeltaType.EQUAL) {
                equal += delta.getSource().getLines().size();
            } else {
                diff += Integer.max(
                        delta.getSource().getLines().size(),
                        delta.getTarget().getLines().size()
                );
            }
        }
    }

    public long getEqual() {
        return equal;
    }

    public long getDiff() {
        return diff;
    }
}
